package com.qfedu.microuser.point.service.impl;

import com.qfedu.common.core.entity.PointInfo;
import com.qfedu.common.core.entity.PointRule;
import com.qfedu.common.core.utils.UserUtils;
import com.qfedu.microuser.point.mapper.PointInfoMapper;
import com.qfedu.microuser.point.service.PointInfoService;
import com.qfedu.microuser.point.service.PointRuleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Classname PointInfoServiceImpl
 * @Description TODO
 * @Date 2025-05-28 14:40
 * @Created by 老任与码
 */
@Service
public class PointInfoServiceImpl implements PointInfoService {

    @Resource
    private PointInfoMapper pointInfoMapper;

    @Resource
    private PointRuleService pointRuleService;

    @Override
    public void remoteAddPoint(Integer pointType) {

        Integer uid = UserUtils.getUid();
        // PointRule pointRule = pointRuleService.ruleInfoByType(pointType);
        List<PointRule> pointRules = pointRuleService.ruleList();
        PointRule pointRule = pointRules.stream()
                .filter(item -> item.getPointType().equals(pointType))
                .findFirst().orElse(null);
        if (pointRule != null) {

            PointInfo pointInfo = new PointInfo();
            pointInfo.setPointType(pointType);
            pointInfo.setPoint(pointRule.getPoint());
            pointInfo.setUid(uid);
            pointInfoMapper.insert(pointInfo);
        }
    }

}
